{header}
<div class="card">
  <div class="card-header">
    操作
  </div>
  <div class="card-body">
    <button type="button" class="btn btn-primary" id="save">保存</button>
  </div>
</div>
<form>
  <div class="form-group">
    <label for="account">提成</label>
    <div class="form-control">{commission}</div>
  </div>
  <div class="form-group">
    <label for="account">账号</label>
    <input type="text" class="form-control" id="account" aria-describedby="account" value="{account}" readonly>
  </div>
  <div class="form-group">
    <label for="email">电子邮箱</label>
    <input type="text" class="form-control" id="email" aria-describedby="email" value="{email}">
  </div>
  <div class="form-group">
    <label for="tel">电话号码</label>
    <input type="text" class="form-control" id="tel" aria-describedby="tel" value="{tel}">
  </div>
  <div class="form-group">
    <label for="alipay_account">支付宝账号</label>
    <input type="text" class="form-control" id="alipay_account" aria-describedby="alipay_account" value="{alipay_account}">
  </div>
  <div class="form-group">
    <label for="alipay_name">支付宝用户名</label>
    <input type="text" class="form-control" id="alipay_name" aria-describedby="alipay_name" value="{alipay_name}">
  </div>
  <div class="form-group">
    <label for="qq_number">QQ号</label>
    <input type="text" class="form-control" id="qq_number" aria-describedby="qq_number" value="{qq_number}">
  </div>
  <div class="form-group">
    <label for="old_password">旧密码（不修改则留空）</label>
    <input type="password" class="form-control" id="old_password">
  </div>
  <div class="form-group">
    <label for="new_password">新密码</label>
    <input type="password" class="form-control" id="new_password">
  </div>
  <div class="form-group">
    <label for="repeat_password">重复密码</label>
    <input type="password" class="form-control" id="repeat_password">
  </div>
  <script type="text/javascript">
    $(function () {
      $('#save').on('click', function () {
        var account = $('#account').val();
        var email = $('#email').val();
        var tel = $('#tel').val();
        var alipay_account = $('#alipay_account').val();
        var alipay_name = $('#alipay_name').val();
        var qq_number = $('#qq_number').val();
        var old_password = $('#old_password').val();
        var new_password = $('#new_password').val();
        var repeat_password = $('#repeat_password').val();

        if (account === '' || email === '' || tel === '' || alipay_account === '' || alipay_name === '' || qq_number === '') {
          layer.alert('表单不能有空', {icon: 0});
          return;
        } else if (account.indexOf('\'') !== -1 || account.indexOf('"') !== -1 || account.indexOf('\\') !== -1 ||
          email.indexOf('\'') !== -1 || email.indexOf('"') !== -1 || email.indexOf('\\') !== -1 ||
          tel.indexOf('\'') !== -1 || tel.indexOf('"') !== -1 || tel.indexOf('\\') !== -1 ||
          alipay_account.indexOf('\'') !== -1 || alipay_account.indexOf('"') !== -1 || alipay_account.indexOf('\\') !== -1 ||
          alipay_name.indexOf('\'') !== -1 || alipay_name.indexOf('"') !== -1 || alipay_name.indexOf('\\') !== -1 ||
          qq_number.indexOf('\'') !== -1 || qq_number.indexOf('"') !== -1 || qq_number.indexOf('\\') !== -1) {
          layer.alert('表单不能含有引号和斜杠', {icon: 0});
          return;
        }
        if (old_password !== '' && new_password !== repeat_password) {
          layer.alert('密码与重复密码不一致', {icon: 0});
          return;
        }
        var save = $('#save');
        save.attr('disabled', true);
        $.ajax({
          url: '{base_url}library/edit_person_info',
          type: 'post',
          data: {
            account: account,
            email: email,
            tel: tel,
            alipay_account: alipay_account,
            alipay_name: alipay_name,
            qq_number: qq_number,
            old_password: old_password,
            new_password: new_password
          },
          success: function (data) {
            var d = data.split(':');
            save.attr('disabled', false);
            if (d.length !== 2) {
              console.error(data);
              layer.alert('服务器返回非法数据', {icon: 2});
              return;
            }
            if (d[0] === 'fail') {
              layer.alert('上传失败:' + d[1], {icon: 2});
              console.error('上传失败:' + d[1]);
            } else if (d[0] === 'success') {
              location.href = '{base_url}copywrite_list';
            } else {
              console.error(data);
              layer.alert('服务器返回多余数据', {icon: 2});
            }
          },
          error: function (data) {
            layer.alert('上传失败', {icon: 2});
            console.error(data.responseText);
          }
        });
      });
    });
  </script>
</form>
{footer}
